package org.nicocube.airain.app.client.ui;

import java.io.Serializable;
import java.util.Date;

import org.nicocube.airain.common.client.form.CheckBoxField;
import org.nicocube.airain.common.client.form.DateField;
import org.nicocube.airain.common.client.form.Form;
import org.nicocube.airain.common.client.form.FormVisitor;
import org.nicocube.airain.common.client.form.TextBoxField;
import org.nicocube.airain.domain.client.character.Gender;
import org.nicocube.airain.domain.client.util.PublisherImpl;
import org.nicocube.airain.domain.client.util.Subscriber;

import com.google.gwt.i18n.client.Constants;

public class PlayerForm implements Form,Serializable {
	private static final long serialVersionUID = 1L;

	private String firstName;
	private String lastName;
	private String email;
	private Date dateOfBirth;
	private Gender gender;
	private String country;
	private String language;
	private boolean acceptNewsLetter;
	private boolean acceptPromotion;
	private boolean acceptPartner;

	private transient PublisherImpl publisherImpl;
	
	public PlayerForm() {
		publisherImpl = new PublisherImpl(this);
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
		publish();
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
		publish();
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
		publish();
	}
	public Date getDateOfBirth() {
		return dateOfBirth;
	}
	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
		publish();
	}
	public Gender getGender() {
		return gender;
	}
	public void setGender(Gender gender) {
		this.gender = gender;
		publish();
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
		publish();
	}
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
		publish();
	}
	public boolean isAcceptNewsLetter() {
		return acceptNewsLetter;
	}
	public void setAcceptNewsLetter(boolean acceptNewsLetter) {
		this.acceptNewsLetter = acceptNewsLetter;
		publish();
	}
	public boolean isAcceptPromotion() {
		return acceptPromotion;
	}
	public void setAcceptPromotion(boolean acceptPromotion) {
		this.acceptPromotion = acceptPromotion;
		publish();
	}
	public boolean isAcceptPartner() {
		return acceptPartner;
	}
	public void setAcceptPartner(boolean acceptPartner) {
		this.acceptPartner = acceptPartner;
		publish();
	}

	@Override
	public void visitFormFields(Constants constants, FormVisitor formVisitor) {
		formVisitor.visit(new TextBoxField("firstName",this,constants) {
			@Override
			protected void setInForm(String value) {
				setFirstName(value);
			}
			@Override
			protected String getInForm() {
				return getFirstName();
			}
		});
		formVisitor.visit(new TextBoxField("lastName",this,constants) {
			@Override
			protected void setInForm(String value) {
				setLastName(value);
			}
			@Override
			protected String getInForm() {
				return getLastName();
			}
		});
		formVisitor.visit(new TextBoxField("email",this,constants) {
			@Override
			protected String getInForm() {
				return getEmail();
			}
			@Override
			protected void setInForm(String value) {
				setEmail(value);
			}
		});
		formVisitor.visit(new DateField("dateOfBirth",this,constants) {
			@Override
			protected Date getInForm() {
				return getDateOfBirth();
			}
			@Override
			protected void setInForm(Date value) {
				setDateOfBirth(value);
			}
		});
		formVisitor.visit(new GenderField("gender",this,constants) {
			@Override
			protected Gender getInForm() {
				return getGender();
			}
			@Override
			protected void setInForm(Gender value) {
				setGender(value);
			}
		});		
		formVisitor.visit(new TextBoxField("country",this,constants) {
			@Override
			protected String getInForm() {
				return getCountry();
			}
			@Override
			protected void setInForm(String value) {
				setCountry(value);
			}
		});
		formVisitor.visit(new TextBoxField("language",this,constants) {
			@Override
			protected void setInForm(String value) {
				setLanguage(value);
			}
			@Override
			protected String getInForm() {
				return getLanguage();
			}
		});
		formVisitor.visit(new CheckBoxField("acceptNewsLetter",this,constants) {
			@Override
			protected Boolean getInForm() {
				return isAcceptNewsLetter();
			}
			@Override
			protected void setInForm(Boolean value) {
				setAcceptNewsLetter(value);
			}
			
		});
		formVisitor.visit(new CheckBoxField("acceptPromotion",this,constants) {
			@Override
			protected Boolean getInForm() {
				return isAcceptPromotion();
			}
			@Override
			protected void setInForm(Boolean value) {
				setAcceptPromotion(value);
			}
			
		});
		formVisitor.visit(new CheckBoxField("acceptPartner",this,constants) {
			@Override
			protected Boolean getInForm() {
				return isAcceptPartner();
			}
			@Override
			protected void setInForm(Boolean value) {
				setAcceptPartner(value);
			}
		});
	}
	
	@Override
	public void publish() {
		publisherImpl.publish();
	}
	@Override
	public void subscribe(Subscriber subscriber) {
		publisherImpl.subscribe(subscriber);
	}
	@Override
	public void unsubscribe(Subscriber subscriber) {
		publisherImpl.unsubscribe(subscriber);
	}

	@Override
	public String toString() {
		return 
		"firstName="+firstName+
		",lastName="+lastName+
		",email="+email+
		",dateOfBirth="+dateOfBirth+
		",gender="+gender+
		",country="+country+
		",language="+language+
		",acceptNewsLetter="+acceptNewsLetter+
		",acceptPromotion="+acceptPromotion+
		",acceptPartner="+acceptPartner;

	}
}
